<?php
/*========================================= JooSam =========================================/
/																							/
/	Extention:		JooSam																	/
/	Created by:		ScriptPlanet.eu															/
/	Site:			http://www.scriptplanet.eu												/
/	Email:			support@scriptplanet.eu													/
/	Support:		http://www.scriptplanet.eu/support										/
/	Copyright:		2011 (c) ScriptPlanet.eu												/
/	License:		CC BY-NC-ND 3.0 ~ http://creativecommons.org/licenses/by-nc-nd/3.0/		/
/	File Version:	0001																	/
/																							/
/========================================== JooSam ========================================*/
// Joomla Security
defined('_JEXEC') or die;
JHTML::_('behavior.mootools');
jimport('joomla.application.component.helper');

$noJooSam = 'No JooSam installed;';

if(JComponentHelper::isEnabled('com_joosam', true)):
//========================// CODE IF JOOSAM EXIST //========================// ?>
<div id="jsamEvtUpdate"></div>

<script>
	
	// Object updater
	function jsamEvtUpdObject(){
		var req;
		
		if(window.XMLHttpRequest){
			req = new XMLHttpRequest();
		}
		else if(window.ActiveXObject){
			req = new ActiveXObject("Microsoft.XMLHTTP");
		}
		else{
			alert("Your Browser Does Not Support This Script - Please Upgrade Your Browser ASAP");
		}
		return req;
	}
	
	// var update event
	var jsamEupd = jsamEvtUpdObject();

	// Load Update object
	function jsamEvtUpdSend(){
		var url = "<?php echo JRoute::_('index.php?option=com_joosam&view=modules&layout=update&format=raw'); ?>";
		jsamEupd.open('post', url ,true);
		jsamEupd.onreadystatechange = jsamEvtUpdHandleResponse;
		jsamEupd.send(null);
	}
	
	// on ready jsam Event Update
	function jsamEvtUpdHandleResponse(){
		if(jsamEupd.readyState == 4 && jsamEupd.status == 200){
			var response = jsamEupd.responseText;
			if(response){
				var target = document.getElementById("jsamEvtUpdate");
				target.innerHTML = response;
				var WeekErr = document.getElementById("jsamWeekError").value;
				var DayErr = document.getElementById("jsamDayError").value;
				var WeekDone = document.getElementById("jsamWeekDone").value;
				var DayDone = document.getElementById("jsamDayDone").value;
				DayErr = parseFloat(DayErr);
				WeekErr = parseFloat(WeekErr);

				if(WeekErr > 0){
					alert('Error while update week events');
				}
				if(DayErr > 0){
					alert('Error while update day events');
				}
			}
		}
	}

	window.onload = jsamEvtUpdSend();
</script>

<?php /*========================// CODE IF JOOSAM EXIST END //========================*/ else: ?>
<script>
	alert("<?php echo $noJooSam; ?>");
</script>
<?php /*========================// END UPDATER //========================*/ endif; ?>